﻿
using MySql.Data.MySqlClient;
using System;
using System.Data;
using System.Text;

namespace REVISIONMAX30.DataObjects
{
    public class ConnectionString : DataObjectBase
    {
        public string Name { get; set; }
        public string Value { get; set; }
        public string MySQLBatchPath { get; set; }
        public ConnectionString()
        {
        }

        public ConnectionString(string pName)
        {
            this.DataObjectGUID = Guid.NewGuid();
            this.Name = pName;
            this.MySQLBatchPath = Common.DefaultMySQLBatchPath;

            this.Created = DateTime.Now;
        }

        public REVISIONMAX30.Frame.FrResultType TestConnection()
        {
            return MySQLDBHandler.TestConnection(this.Value);
        }

        public MySqlConnectionStringBuilder ConnectionStringBuilder
        {
            get
            {
                return new MySqlConnectionStringBuilder(this.Value);
            }
        }

        public void SetValue(string pServer, string pDataBase, uint pPort, string pUserID, string pPassword)
        {
            var tConnectionStringBuilder = new MySqlConnectionStringBuilder();

            tConnectionStringBuilder.Database = pServer;
            tConnectionStringBuilder.Server = pDataBase;
            tConnectionStringBuilder.Port = pPort;
            tConnectionStringBuilder.UserID = pUserID;
            tConnectionStringBuilder.Password = pPassword;

            this.Value = tConnectionStringBuilder.ConnectionString;
        }


    }
}

